#!/bin/bash 

bin=`dirname "$0"`
bin=`cd "$bin"; pwd`

# Decompression plugins.
cd "${bin}"/plugins/
for i in `ls *gz 2>/dev/null`; do tar zxf $i; done
for i in `ls *bz2 2>/dev/null`; do tar jxf $i; done
cd - > /dev/null

# Make emacs root path corrections.
cp "${bin}"/.emacs "${bin}"/.emacs.tmp
sed -i s,~/emacs,${bin},g "${bin}"/.emacs.tmp

# Backup old .emacs and copy new .emacs
dateTime=`date '+%F_%T'`
dotEmacs=~/.emacs
if [[ -f "$dotEmacs" && ! -L "$dotEmacs" ]]; then
    mv "$dotEmacs" "$dotEmacs.$dateTime"
fi
mv "${bin}"/.emacs.tmp $dotEmacs
